<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
require_once 'Base/BaseWidalReactions.class.php';

Class WidalReactions {

	public function  __construct() {
			if( true == isset( $_SERVER['connection'] ) ) {
				$this->connection = $_SERVER['connection'];
			}
	}

	
	/*******************************************************************************************
	******************************** Fetch Functions *******************************************
	*******************************************************************************************/

	public function fetchSql( $strSql ) {
		$result = $this->connection->RunQuery( $strSql );
		$arrobjWidalReactions = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objWidalReactions = new BaseWidalReactions();
			$objWidalReactions->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objWidalReactions->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objWidalReactions->setCasePaperId( ( true == isset( $row["case_paper_id"] ) ) ? $row["case_paper_id"] : 'NULL' );
			$objWidalReactions->setDescription( ( true == isset( $row["description"] ) ) ? $row["description"] : 'NULL' );
			$objWidalReactions->setDoctorId( ( true == isset( $row["doctor_id"] ) ) ? $row["doctor_id"] : 'NULL' );
			$objWidalReactions->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objWidalReactions->setDocumentAttachmentId( ( true == isset( $row["document_attachment_id"] ) ) ? $row["document_attachment_id"] : 'NULL' );
			$objWidalReactions->setAttachmentPath( ( true == isset( $row["attachment_path"] ) ) ? $row["attachment_path"] : 'NULL' );
			array_push( $arrobjWidalReactions, $objWidalReactions );
		}
		return $arrobjWidalReactions;
	}
	public function fetchAllWidalReactions() {
		$result = $this->connection->RunQuery("SELECT * FROM WIDAL_REACTIONS");
		$arrobjWidalReactions = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objWidalReactions = new BaseWidalReactions();
			$objWidalReactions->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objWidalReactions->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objWidalReactions->setCasePaperId( ( true == isset( $row["case_paper_id"] ) ) ? $row["case_paper_id"] : 'NULL' );
			$objWidalReactions->setDescription( ( true == isset( $row["description"] ) ) ? $row["description"] : 'NULL' );
			$objWidalReactions->setDoctorId( ( true == isset( $row["doctor_id"] ) ) ? $row["doctor_id"] : 'NULL' );
			$objWidalReactions->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objWidalReactions->setDocumentAttachmentId( ( true == isset( $row["document_attachment_id"] ) ) ? $row["document_attachment_id"] : 'NULL' );
			$objWidalReactions->setAttachmentPath( ( true == isset( $row["attachment_path"] ) ) ? $row["attachment_path"] : 'NULL' );
			array_push( $arrobjWidalReactions, $objWidalReactions);
		}
		return $arrobjWidalReactions;
	}
	public function fetchAllWidalReactionsByIds( $arrintIds ) {
		$result = $this->connection->RunQuery("SELECT * FROM WIDAL_REACTIONS WHERE id IN ( implode( "," $arrintIds ) " );
		$arrobjWidalReactions = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objWidalReactions->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objWidalReactions->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objWidalReactions->setCasePaperId( ( true == isset( $row["case_paper_id"] ) ) ? $row["case_paper_id"] : 'NULL' );
			$objWidalReactions->setDescription( ( true == isset( $row["description"] ) ) ? $row["description"] : 'NULL' );
			$objWidalReactions->setDoctorId( ( true == isset( $row["doctor_id"] ) ) ? $row["doctor_id"] : 'NULL' );
			$objWidalReactions->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objWidalReactions->setDocumentAttachmentId( ( true == isset( $row["document_attachment_id"] ) ) ? $row["document_attachment_id"] : 'NULL' );
			$objWidalReactions->setAttachmentPath( ( true == isset( $row["attachment_path"] ) ) ? $row["attachment_path"] : 'NULL' );
			array_push( $arrobjWidalReactions, $objWidalReactions );
		}
		return $arrobjWidalReactions;
	}

	public function fetchWidalReactionsById( $intId ) {
		$result = $this->connection->RunQuery( "SELECT * FROM WIDAL_REACTIONS WHERE id = " . $intId );
			$objWidalReactions = NULL;
		while($row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objWidalReactions = new BaseWidalReactions();
			$objWidalReactions->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objWidalReactions->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objWidalReactions->setCasePaperId( ( true == isset( $row["case_paper_id"] ) ) ? $row["case_paper_id"] : 'NULL' );
			$objWidalReactions->setDescription( ( true == isset( $row["description"] ) ) ? $row["description"] : 'NULL' );
			$objWidalReactions->setDoctorId( ( true == isset( $row["doctor_id"] ) ) ? $row["doctor_id"] : 'NULL' );
			$objWidalReactions->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objWidalReactions->setDocumentAttachmentId( ( true == isset( $row["document_attachment_id"] ) ) ? $row["document_attachment_id"] : 'NULL' );
			$objWidalReactions->setAttachmentPath( ( true == isset( $row["attachment_path"] ) ) ? $row["attachment_path"] : 'NULL' );
		}
		return $objWidalReactions;
	}

	public function GetKeysOrderBy($column, $order){
		$keys = array(); $i = 0;
		$result = $this->connection->RunQuery("SELECT id from widal_reactions order by $column $order");
			while($row = $result->fetch_array(MYSQLI_ASSOC)){
				$keys[$i] = $row["id"];
				$i++;
			}
	return $keys;
	}

	public function endWidalReactions(){
		$this->connection->CloseMysql();
	}

}